package com.rede.didiok.user.modulelist.rank.web;


import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.rede.didiok.common.annotion.AvoidRepeatableCommit.AvoidRepeatableCommit;
import com.rede.didiok.common.dto.rank.RankCategoryDto;
import com.rede.didiok.common.exception.ThrowableUtils;
import com.rede.didiok.common.utils.ResultUtil;
import com.rede.didiok.common.validator.group.Delete;
import com.rede.didiok.common.validator.group.GetList;
import com.rede.didiok.common.validator.group.Insert;
import com.rede.didiok.common.validator.group.Update;
import com.rede.didiok.user.modulelist.rank.service.RankCategoryService;

/**
 * 榜单分类表 RestApi
 *
 * @author 陌溪
 * @date 2018年9月24日15:45:18
 */
@RestController
@RequestMapping("/admin/feign/rankCategory")
@Api(value = "榜单分类相关接口", tags = {"榜单分类相关接口"})
@Slf4j
public class RankCategoryController {

    @Autowired
    private RankCategoryService rankCategoryService;

    @ApiOperation(value = "获取榜单分类列表", notes = "获取榜单分类列表", response = String.class)
    @PostMapping("/getList")
    public String getList(@Validated({GetList.class}) @RequestBody RankCategoryDto rankCategoryDto, BindingResult result) {

        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        log.info("获取榜单分类列表");
        return ResultUtil.successWithData(rankCategoryService.getPageList(rankCategoryDto));
    }

    @AvoidRepeatableCommit
    @ApiOperation(value = "增加榜单分类", notes = "增加榜单分类", response = String.class)
    @PostMapping("/add")
    public String add(@Validated({Insert.class}) @RequestBody RankCategoryDto rankCategoryDto, BindingResult result) {

        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        log.info("增加榜单分类");
        return rankCategoryService.addRankCategory(rankCategoryDto);
    }

    @ApiOperation(value = "编辑榜单分类", notes = "编辑榜单分类", response = String.class)
    @PostMapping("/edit")
    public String edit(@Validated({Update.class}) @RequestBody RankCategoryDto rankCategoryDto, BindingResult result) {

        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        log.info("编辑榜单分类");
        return rankCategoryService.editRankCategory(rankCategoryDto);
    }

    @ApiOperation(value = "批量删除榜单分类", notes = "批量删除榜单分类", response = String.class)
    @PostMapping("/deleteBatch")
    public String delete(@Validated({Delete.class}) @RequestBody List<RankCategoryDto> rankCategoryDtoList, BindingResult result) {

        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        log.info("批量删除榜单分类");
        return rankCategoryService.deleteBatchRankCategory(rankCategoryDtoList);
    }

    @ApiOperation(value = "置顶分类", notes = "置顶分类", response = String.class)
    @PostMapping("/stick")
    public String stick(@Validated({Delete.class}) @RequestBody RankCategoryDto rankCategoryDto, BindingResult result) {

        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        log.info("置顶分类");
        return rankCategoryService.stickRankCategory(rankCategoryDto);

    }

}

